<?php
/*
 * $Id: MySQLiConnectionManager.class.php 218 2009-10-27 02:42:02Z takuji.mezawa $
 * 
 * (C) 2009, Mezawa Takuji, EzoGP (http://ezogp.sourceforge.jp/).
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// オブジェクト参照定義
require_once "model/dao/ConnectionManager.class.php";

/**
 * MySQL(MySQLi)データベース接続マネージャクラス。
 * 
 * @author     $Author: takuji.mezawa $  (EzoGP)
 * @version    $Revision: 218 $, SyracavaPHP
 * @package    model
 * @subpackage dao
 */
class MySQLiConnectionManager extends ConnectionManager {
    private static $sqlxml;                 // SQL定義リソース
    private static $log;                    // ロガー
    private static $typename = __CLASS__;   // 自身のクラス名
    
    /**
     * (non-PHPdoc)
     * @see syracava/libs/model/dao/ConnectionManager#connect($sqlxml)
     */
    public function &connect($sqlxml) {
        self::$log =& LoggingObject::getLogger();
        
        self::$log->start(__METHOD__);
        
        $_dbConfig = LocalSession::getAttribute("mysqlConfig");
        $_conn =& MDB2::singleton($_dbConfig['dsn'], $_dbConfig['opt']);
        
        if (MDB2::isError($_conn)) {
            $_msg = Message::getMessage(
                "fatal.egp.db-connection", array(self::$typename, $_conn->getCode(), $_conn->getMessage())
            );
            self::$log->fatal($_msg);
            exit;
        }
        
        $_conn->setFetchMode($_dbConfig['fetchMode']);
        
        self::$sqlxml = simplexml_load_file($sqlxml);
        
        self::$log->finish(__METHOD__);
        
        return $_conn;
    }
    
    /**
     * (non-PHPdoc)
     * @see syracava/libs/model/dao/ConnectionManager#getSqlXmlConfig()
     */
    public function getSqlXmlConfig() {
        return self::$sqlxml;
    }
}
?>